package cc.wsyw126.java.sycnAndVolaTest;

/**
 * Created by junpeng.yang on 16/11/29.
 */
public class SyncTest {
    public int inc = 0;

    public synchronized void increase() {
        inc++;
    }

    public static void main(String[] args) {
        final SyncTest test = new SyncTest();
        for (int i = 0; i < 10; i++) {
            new Thread() {
                public void run() {
                    for (int j = 0; j < 1000; j++)
                        test.increase();
                }

                ;
            }.start();
            System.out.println("Thread.activeCount() = " + Thread.activeCount());
        }

        while (Thread.activeCount() > 2)  //保证前面的线程都执行完
            Thread.yield();
        System.out.println(test.inc);
    }
}
